package com.kuzufang.modules.main.roommate;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kuzufang.R;
import com.kuzufang.base.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by songyuanjin on 2017/9/19.
 */

public class RoomConfigurationAdapter extends BaseAdapter<RoomConfigurationAdapter.ConfigItem, RoomConfigurationAdapter.RoomConfigHolder> {

    public RoomConfigurationAdapter(Context ctx) {
        super(ctx);

        List<ConfigItem> configItems = new ArrayList<>();
        ConfigItem configItem1 = new ConfigItem(R.drawable.icon_tv, "电视机");
        ConfigItem configItem2 = new ConfigItem(R.drawable.icon_air_conditioning, "空调");
        ConfigItem configItem3 = new ConfigItem(R.drawable.icon_bed, "床");
        ConfigItem configItem4 = new ConfigItem(R.drawable.icon_destock, "书桌");
        ConfigItem configItem5 = new ConfigItem(R.drawable.icon_wash_cloth, "洗衣机");
        ConfigItem configItem6 = new ConfigItem(R.drawable.icon_hot_bash_room, "热水器");
        ConfigItem configItem7 = new ConfigItem(R.drawable.icon_wifi, "WIFI");
        ConfigItem configItem8 = new ConfigItem(R.drawable.icon_cloth, "衣橱");

        configItems.add(configItem1);
        configItems.add(configItem2);
        configItems.add(configItem3);
        configItems.add(configItem4);
        configItems.add(configItem5);
        configItems.add(configItem6);
        configItems.add(configItem7);
        configItems.add(configItem8);

        addAll(configItems);
        notifyDataSetChanged();

    }

    @Override
    protected void bindViewHolderData(RoomConfigHolder viewHolder, ConfigItem data, int position) {
        viewHolder.bindData(data);
    }

    @Override
    public RoomConfigHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mCtx).inflate(R.layout.item_room_config, parent, false);
        return new RoomConfigHolder(view);
    }

    class RoomConfigHolder extends RecyclerView.ViewHolder {
        private ImageView roomIcon;
        private TextView roomName;

        public RoomConfigHolder(View itemView) {
            super(itemView);
            roomIcon = (ImageView) itemView.findViewById(R.id.room_config_icon);
            roomName = (TextView) itemView.findViewById(R.id.room_config_name);
        }

        public void bindData(ConfigItem data) {
            roomIcon.setImageResource(data.resId);
            roomName.setText(data.getName());
        }
    }

    class ConfigItem {
        private int resId;
        private String name;

        public ConfigItem(int resId, String name) {
            this.resId = resId;
            this.name = name;
        }

        public int getResId() {
            return resId;
        }

        public void setResId(int resId) {
            this.resId = resId;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
